package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CategoryController
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-10-29 23:09
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product")
public class CategoryController {
    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

    /**
     * 查询商品的一级分类
     * http://127.0.0.1/admin/product/getCategory1
     */
    @GetMapping("getCategory1")
    private Result getCategory1(){
        List<BaseCategory1> list = baseCategory1Service.list();
        return Result.ok(list);
    }

    /**
     * 查询商品的二级分类
     * http://127.0.0.1/admin/product/getCategory2/5
     * @return
     */
    @GetMapping("getCategory2/{category1Id}")
    private Result getCategory2(@PathVariable Long category1Id){
        QueryWrapper<BaseCategory2> wrapper = new QueryWrapper<>();
        wrapper.eq("category1_id",category1Id);
        List<BaseCategory2> list = baseCategory2Service.list(wrapper);
        return Result.ok(list);
    }

    /**
     * 查询商品的三级分类
     * http://127.0.0.1/admin/product/getCategory3/17
     * @return
     */
    @GetMapping("getCategory3/{category2Id}")
    private Result getCategory3(@PathVariable Long category2Id){
        QueryWrapper<BaseCategory3> wrapper = new QueryWrapper<>();
        wrapper.eq("category2_id",category2Id);
        List<BaseCategory3> list = baseCategory3Service.list(wrapper);
        return Result.ok(list);
    }
}
